package com.audaque.springboot.foshanupload.web.webdemo.controller;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.audaque.springboot.foshanupload.log.anno.WebLogAnno;
import com.audaque.springboot.foshanupload.web.anno.RAnno;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zgb
 * @desc ...
 * @date 2023-07-17 15:13:30
 */
@Slf4j
@RestController
@RequestMapping("transmittableThreadLocal")
public class TransmittableThreadLocalController {
    public static final TransmittableThreadLocal<String> context = new TransmittableThreadLocal<>();

    @RAnno
    @WebLogAnno
    @GetMapping("/setget")
    public String setget() throws Exception {
        context.set("value-set-in-parent");
        String value = context.get();
        log.debug("value:" + value);
        return value;
    }


    @RAnno
    @WebLogAnno
    @GetMapping("/get")
    public String get() throws Exception {
        String value = context.get();
        log.debug("value:" + value);
        return value;
    }

    @RAnno
    @WebLogAnno
    @GetMapping("/removeget")
    public String removeget() throws Exception {
        context.remove();
        String value = context.get();
        log.debug("value:" + value);
        return value;
    }


}
